{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Maximum Consecutive Floors Without Special Floors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxConsecutive"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #不含特殊楼层的最大连续楼层数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>Alice 管理着一家公司，并租用大楼的部分楼层作为办公空间。Alice 决定将一些楼层作为 <strong>特殊楼层</strong> ，仅用于放松。</p>\n",
    "\n",
    "<p>给你两个整数 <code>bottom</code> 和 <code>top</code> ，表示 Alice 租用了从 <code>bottom</code> 到 <code>top</code>（含 <code>bottom</code> 和 <code>top</code> 在内）的所有楼层。另给你一个整数数组 <code>special</code> ，其中 <code>special[i]</code> 表示&nbsp; Alice 指定用于放松的特殊楼层。</p>\n",
    "\n",
    "<p>返回不含特殊楼层的 <strong>最大</strong> 连续楼层数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>bottom = 2, top = 9, special = [4,6]\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>下面列出的是不含特殊楼层的连续楼层范围：\n",
    "- (2, 3) ，楼层数为 2 。\n",
    "- (5, 5) ，楼层数为 1 。\n",
    "- (7, 9) ，楼层数为 3 。\n",
    "因此，返回最大连续楼层数 3 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>bottom = 6, top = 8, special = [7,6,8]\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>每层楼都被规划为特殊楼层，所以返回 0 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= special.length &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>1 &lt;= bottom &lt;= special[i] &lt;= top &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>special</code> 中的所有值 <strong>互不相同</strong></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [maximum-consecutive-floors-without-special-floors](https://leetcode.cn/problems/maximum-consecutive-floors-without-special-floors/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [maximum-consecutive-floors-without-special-floors](https://leetcode.cn/problems/maximum-consecutive-floors-without-special-floors/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['2\\n9\\n[4,6]', '6\\n8\\n[7,6,8]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom - 1, top + 1])\n",
    "        special.sort()\n",
    "        \n",
    "        n = len(special)\n",
    "        ans = 0\n",
    "        for i in range(n - 1):\n",
    "            ans = max(ans, special[i + 1] - special[i] - 1)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        special.append(top+1)\n",
    "        ans = 0\n",
    "        last = bottom - 1\n",
    "        for n in special:\n",
    "            ans = max(ans, n-last-1)\n",
    "            last = n\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        if special[0]!=bottom:\n",
    "            special=[bottom-1]+special\n",
    "        if special[-1]!=top:\n",
    "            special.append(top+1)\n",
    "        mx=0\n",
    "        for i in range(1,len(special)):\n",
    "            print(special[i]-1-special[i-1])\n",
    "            mx=max(mx,special[i]-1-special[i-1])\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom - 1, top + 1])\n",
    "        special.sort()\n",
    "        \n",
    "        n = len(special)\n",
    "        ans = 0\n",
    "        for i in range(n - 1):\n",
    "            ans = max(ans, special[i + 1] - special[i] - 1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        res = 0\n",
    "        special = [bottom-1] + special + [top+1]\n",
    "        for i in range(1, len(special)):\n",
    "            res = max(res, special[i] - special[i-1] - 1)\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "      special.sort()\n",
    "      ans = max(special[0]-bottom,top-special[-1])\n",
    "      for x,y in pairwise(special):\n",
    "        ans = max(ans,y-x-1)\n",
    "      return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        special = [bottom-1]+special+[top+1]\n",
    "        ans = 0\n",
    "        for i, s in  enumerate(special[:-1]):\n",
    "            ans = max(ans, special[i+1]-special[i]-1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom - 1, top + 1])\n",
    "        special.sort()\n",
    "        n = len(special)\n",
    "        ans = 0\n",
    "        for i in range(n - 1):\n",
    "            ans = max(ans, special[i + 1] - special[i] - 1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        # 把 bottom−1和 top+1视作两个特殊楼层，从而简化代码逻辑。\n",
    "        special.append(bottom - 1)\n",
    "        special.append(top + 1)\n",
    "        special.sort()\n",
    "        return max(y - x - 1 for x,y in pairwise(special))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special += [bottom - 1, top + 1]\n",
    "        special.sort()\n",
    "\n",
    "        return max(y - x - 1 for x, y in pairwise(special))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.append(top+1)\n",
    "        special.append(bottom-1)\n",
    "        special.sort()\n",
    "        return max(s2 - s1 - 1 for s1, s2 in zip(special, special[1:]))\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.append(bottom - 1)\n",
    "        special.append(top + 1)\n",
    "        special.sort()\n",
    "        return max(y - x - 1 for x, y in pairwise(special))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.append(bottom - 1)\n",
    "        special.append(top + 1)\n",
    "\n",
    "        special.sort()\n",
    "\n",
    "        result = 0\n",
    "        for i in range(len(special) - 1):\n",
    "            result = max(result, special[i + 1] - special[i] - 1)\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom - 1, top + 1])\n",
    "        special.sort()\n",
    "        \n",
    "        n = len(special)\n",
    "        ans = 0\n",
    "        for i in range(n - 1):\n",
    "            ans = max(ans, special[i + 1] - special[i] - 1)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom-1, top+1])\n",
    "        special.sort()\n",
    "\n",
    "        result = 0\n",
    "        for i in range(len(special)-1):\n",
    "            result = max(result, special[i+1]-special[i]-1)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.append(bottom - 1)\n",
    "        special.append(top + 1)\n",
    "        special.sort()\n",
    "        return max(b - a - 1 for a, b in pairwise(special))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        if special[0]!=bottom:\n",
    "            special=[bottom-1]+special\n",
    "        if special[-1]!=top:\n",
    "            special.append(top+1)\n",
    "        mx=0\n",
    "        for i in range(1,len(special)):\n",
    "            mx=max(mx,special[i]-1-special[i-1])\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        # 1 <= special.length <= 105\n",
    "        special.extend([bottom-1, top+1])\n",
    "        special.sort()\n",
    "        \n",
    "        mx = 0\n",
    "        n = len(special)\n",
    "        for i in range(1, n):\n",
    "            mx = max(mx, special[i]-special[i-1]-1)\n",
    "            \n",
    "        return mx\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.append(bottom - 1)\n",
    "        special.append(top + 1)\n",
    "        special.sort()\n",
    "        return max(y - x - 1 for x, y in pairwise(special))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.extend([bottom - 1, top + 1])\n",
    "        special.sort()\n",
    "        \n",
    "        n = len(special)\n",
    "        ans = 0\n",
    "        for i in range(n - 1):\n",
    "            ans = max(ans, special[i + 1] - special[i] - 1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        special = [bottom - 1] + special + [top + 1]        \n",
    "        res = 0\n",
    "        for i in range(1, len(special)):\n",
    "            res = max(res, special[i] - special[i - 1] - 1)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        if bottom-1 not in special: special.append(bottom-1)\n",
    "        if top+1 not in special: special.append(top+1)\n",
    "        special.sort()\n",
    "\n",
    "        return max(special[k+1]-special[k]-1 for k in range(len(special)-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        num1 = special[0] - bottom\n",
    "        num2 = top - special[-1]\n",
    "        num3 = 0\n",
    "        i, j = 0, 1\n",
    "        while j < len(special):\n",
    "            num3 = max(num3, special[j]-special[i]-1)\n",
    "            i+=1\n",
    "            j+=1\n",
    "        return max(num1, num2, num3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        num1 = special[0] - bottom\n",
    "        num2 = top - special[-1]\n",
    "        num3 = 0\n",
    "        for x,y in pairwise(special):\n",
    "            num3 = max(num3, y-x-1)\n",
    "        return max(num1, num2, num3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "\n",
    "\n",
    "        i = 0\n",
    "        ans = 0\n",
    "\n",
    "\n",
    "        while i <= len(special):\n",
    "            if i == 0:\n",
    "                left = 0\n",
    "                right = special[i] - 1\n",
    "            elif i == len(special):\n",
    "                left = special[i - 1] + 1\n",
    "                right = int(1e9)\n",
    "            else:\n",
    "                left = special[i - 1] + 1\n",
    "                right = special[i] - 1\n",
    "\n",
    "            if left > right:\n",
    "                i += 1\n",
    "                continue\n",
    "            \n",
    "            l = max(left, bottom)\n",
    "            r = min(right, top)\n",
    "\n",
    "            ans = max(ans, max(r - l + 1, 0))\n",
    "            i += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        res = max(special[0] - bottom, top - special[-1]) + 1\n",
    "        for i in range(len(special) - 1):\n",
    "            res = max(res, special[i+1] - special[i])\n",
    "        return res - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        x = 0\n",
    "        for i in range(1, len(special)):\n",
    "            x = max(x, special[i]-special[i-1])\n",
    "        return max(x-1, special[0]-bottom, top-special[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        ans = 0\n",
    "        n = len(special)\n",
    "        for i in range(n):\n",
    "            if i == 0:\n",
    "                ans = max(special[i] - bottom, ans)\n",
    "            else:\n",
    "                ans = max(special[i] - special[i-1]-1, ans)\n",
    "        ans = max(top-special[i], ans)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        res = max(special[0] - bottom, top - special[-1])\n",
    "        for i in range(1, len(special)):\n",
    "            res = max(res, special[i] - special[i-1] - 1)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        num1 = special[0] - bottom\n",
    "        num2 = top - special[-1]\n",
    "        num3 = 0\n",
    "        # i, j = 0, 1\n",
    "        # while j < len(special):\n",
    "        #     num3 = max(num3, special[j]-special[i]-1)\n",
    "        #     i+=1\n",
    "        #     j+=1\n",
    "        for x,y in pairwise(special):\n",
    "            num3 = max(num3, y-x-1)\n",
    "        return max(num1, num2, num3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        '''k=bottom\n",
    "        flag=0\n",
    "        flag_lis=[]\n",
    "        while(k<=top):\n",
    "            if k not in special:\n",
    "                flag+=1\n",
    "            else:\n",
    "                flag_lis.append(flag)\n",
    "                flag=0\n",
    "            k=k+1\n",
    "        flag_lis.append(flag)\n",
    "        return max(flag_lis)'''\n",
    "        special.append(bottom-1)\n",
    "        special.append(top+1)\n",
    "        special.sort()\n",
    "        return max([special[i+1]-special[i]-1 for i in range(0,len(special)-1)])\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        res = max(special[0] - bottom, top - special[-1])\n",
    "        for i in range(1, len(special)):\n",
    "            res = max(res, special[i] - special[i-1] - 1)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        special = [bottom - 1] + special + [top + 1]\n",
    "        ans = 0\n",
    "        for a, b in pairwise(special):\n",
    "            if b - a - 1 > ans:\n",
    "                ans = b - a - 1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        special = [bottom - 1] + special + [top + 1]\n",
    "        ans = 0\n",
    "        for a, b in pairwise(special):\n",
    "            if b - a - 1 > ans:\n",
    "                ans = b - a - 1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        pre = bottom\n",
    "        ans = 0\n",
    "        for c in special:\n",
    "            ans = max(ans, c - pre)\n",
    "            pre = c + 1\n",
    "        ans = max(ans, top - pre + 1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        num1 = special[0] - bottom\n",
    "        num2 = top - special[-1]\n",
    "        num3 = 0\n",
    "        i, j = 0, 1\n",
    "        while j < len(special):\n",
    "            num3 = max(num3, special[j]-special[i]-1)\n",
    "            i+=1\n",
    "            j+=1\n",
    "        return max(num1, num2, num3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        a = [special[i+1]-special[i]-1 for i in range(len(special)-1)]\n",
    "        a.append(special[0]-bottom)\n",
    "        a.append(top-special[-1])\n",
    "        return max(a)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        ans = 0\n",
    "        a = [bottom - 1] + special + [top + 1]\n",
    "        n = len(a)\n",
    "        for i in range(1, n):\n",
    "            ans = max(ans, a[i] - a[i - 1] - 1)\n",
    "        return ans\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        special.sort()\n",
    "        L = [bottom-1]\n",
    "        L.extend(special)\n",
    "        L.append(top+1)\n",
    "        res = -inf\n",
    "        for i in range(1,len(L)):\n",
    "            res = max(res,L[i]-L[i-1]-1)\n",
    "        return res if res != -inf else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:\n",
    "        ans = 0\n",
    "        special.sort()\n",
    "        ans = max(special[0] - bottom, top - special[-1])\n",
    "        for i in range(1, len(special)):\n",
    "            ans = max(ans, special[i] - special[i-1] - 1)\n",
    "        return ans"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
